#include "store.h"

MyStore::MyStore(QWidget *parent) : QWidget(parent)
{
    //设置窗口固定尺寸
    setFixedSize(800,580);
    //设置标题
   lab.setText("战机商店");
   lab.setParent(this);
   lab.move(310,15);
   QFont font("华文楷体",25,75);
   lab.setFont(font);
   pe.setColor(QPalette::WindowText,Qt::blue);
   lab.setPalette(pe);

    //窗口透明化
    setAttribute(Qt::WA_TranslucentBackground,true);
    //设置无边框
    setWindowFlags(Qt::FramelessWindowHint);

    //返回
    ReturnMain=new QPushButton(this);
    ReturnMain->setFixedSize(50,50);
    ReturnMain->setIcon(QIcon(":/rec.image/main.png"));
    ReturnMain->move(700,60);
    connect(ReturnMain,&QPushButton::clicked,[=](){
         btn_music->play();
        this->close();
    });

    //购买按钮
    //战机2
    Hero_Btn2=new QPushButton;
    Hero_Btn2->setParent(this);
    Hero_Btn2->setIcon(QIcon(":/rec.image/buy.png"));
    Hero_Btn2->setIconSize(QSize(100,40));
    Hero_Btn2->setFixedSize(100,40);
    Hero_Btn2->move(200,220);
    Hero_Btn2->setFlat(true);
    Hero_Btn2->setAttribute(Qt::WA_TranslucentBackground);
    //放置战机图片
    QLabel* l2=new QLabel;
    l2->setParent(this);
    QPixmap p2;
    p2.load(HERO_PATH2);
    l2->setPixmap(p2);
    l2->move(190,80);
    QLabel*l2_gold=new QLabel;
    l2_gold->setParent(this);
    //放置金币图片
    QPixmap p2_gold;
    p2_gold.load(":/rec.image/gold2.png");
    l2_gold->setPixmap(p2_gold);
    l2_gold->move(220,200);
    l2_gold->setFixedSize(20,20);
    //显示价格
    QLabel*l2_num=new QLabel;
    l2_num->setParent(this);
    l2_num->setText(QString::number(HERO2_VALUE));
    l2_num->move(240,200);
    l2_num->setStyleSheet("color:Yellow");

    //点击按钮 购买
    connect(Hero_Btn2,&QPushButton::clicked,[=](){
         btn_music->play();
        //弹出对话框
        QMessageBox msgBox;
        //对话框主题
        msgBox.setInformativeText("   是否购买？  ");
       // 对话框选项
        msgBox.setStandardButtons(QMessageBox::Yes |  QMessageBox::Cancel);
        //msgBox.setDefaultButton(QMessageBox::Save);
        //对话框图片
        QPixmap pix;
        pix.load(":/rec.image/Myplane02.png");
        msgBox.setIconPixmap(pix);
        msgBox.setWindowTitle("购买战机");
        msgBox.setWindowIcon(QIcon(":/rec.image/Icon.png"));

        int ret = msgBox.exec();
        switch (ret) {
        case QMessageBox::Yes:
            if(gold_num<HERO2_VALUE)
            {
                  QMessageBox::warning(this,"warn"," 金币不够");
            }
            else {
                gold_num-=HERO2_VALUE;
                emit(BuyHero2());
                Hero_Btn2->setIcon(QIcon(":/rec.image/on.png"));
            }


          }
    });









    //战机3
    Hero_Btn3=new QPushButton;
    Hero_Btn3->setParent(this);
    Hero_Btn3->setIcon(QIcon(":/rec.image/buy.png"));
    Hero_Btn3->setIconSize(QSize(100,40));
    Hero_Btn3->setFixedSize(100,40);
    Hero_Btn3->move(500,220);
    Hero_Btn3->setFlat(true);
    Hero_Btn3->setAttribute(Qt::WA_TranslucentBackground);
    QLabel* l3=new QLabel;
    l3->setParent(this);
    QPixmap p3;
    p3.load(HERO_PATH3);
    l3->setPixmap(p3);
    l3->move(490,100);
    QLabel*l3_gold=new QLabel;
    l3_gold->setParent(this);
    QPixmap p3_gold;
    p3_gold.load(":/rec.image/gold2.png");
    l3_gold->setPixmap(p3_gold);
    l3_gold->move(520,200);
    l3_gold->setFixedSize(20,20);
    QLabel*l3_num=new QLabel;
    l3_num->setParent(this);
    l3_num->setText(QString::number(HERO3_VALUE));
    l3_num->move(540,200);
    l3_num->setStyleSheet("color:Yellow");

    //点击按钮 购买
    connect(Hero_Btn3,&QPushButton::clicked,[=](){
         btn_music->play();
        //弹出对话框
        QMessageBox msgBox;
        //对话框主题
        msgBox.setInformativeText("   是否购买？  ");
       // 对话框选项
        msgBox.setStandardButtons(QMessageBox::Yes |  QMessageBox::Cancel);
        //msgBox.setDefaultButton(QMessageBox::Save);
        //对话框图片
        QPixmap pix;
        pix.load(HERO_PATH3);
        msgBox.setIconPixmap(pix);
        msgBox.setWindowTitle("购买战机");
        msgBox.setWindowIcon(QIcon(":/rec.image/Icon.png"));

        int ret = msgBox.exec();
        switch (ret) {
        case QMessageBox::Yes:
            if(gold_num<HERO3_VALUE)
            {
                  QMessageBox::warning(this,"warn"," 金币不够");
            }
            else {
                gold_num-=HERO2_VALUE;
                emit(BuyHero3());
                Hero_Btn3->setIcon(QIcon(":/rec.image/on.png"));
            }


          }
    });










    //僚机一
    Wing_Btn1=new QPushButton;
    Wing_Btn1->setParent(this);
    Wing_Btn1->setIcon(QIcon(":/rec.image/buy.png"));
    Wing_Btn1->setIconSize(QSize(100,40));
    Wing_Btn1->setFixedSize(100,40);
    Wing_Btn1->move(100,350);
    Wing_Btn1->setFlat(true);
    Wing_Btn1->setAttribute(Qt::WA_TranslucentBackground);


    QLabel* l4=new QLabel;
    l4->setParent(this);
    QPixmap p4;
    p4.load(WING_PATH1);
    l4->setPixmap(p4);
    l4->move(130,250);
    QLabel*l4_gold=new QLabel;
    l4_gold->setParent(this);
    QPixmap p4_gold;
    p4_gold.load(":/rec.image/gold2.png");
    l4_gold->setPixmap(p4_gold);
    l4_gold->move(130,330);
    l4_gold->setFixedSize(20,20);
    QLabel*l4_num=new QLabel;
    l4_num->setParent(this);
    l4_num->setText(QString::number(WING1_VALUE));
    l4_num->move(150,330);
    l4_num->setStyleSheet("color:Yellow");


    //点击按钮 购买
    connect(Wing_Btn1,&QPushButton::clicked,[=](){
         btn_music->play();
        //弹出对话框
        QMessageBox msgBox;
        //对话框主题
        msgBox.setInformativeText("   是否购买？  ");
       // 对话框选项
        msgBox.setStandardButtons(QMessageBox::Yes |  QMessageBox::Cancel);
        //msgBox.setDefaultButton(QMessageBox::Save);
        //对话框图片
        QPixmap pix;
        pix.load(WING_PATH1);
        msgBox.setIconPixmap(pix);
        msgBox.setWindowTitle("购买战机");
        msgBox.setWindowIcon(QIcon(":/rec.image/Icon.png"));

        int ret = msgBox.exec();
        switch (ret) {
        case QMessageBox::Yes:
            if(gold_num<WING1_VALUE)
            {
                  QMessageBox::warning(this,"warn"," 金币不够");
            }
            else {
                gold_num-=WING1_VALUE;
                emit(BuyWing1());
                Wing_Btn1->setIcon(QIcon(":/rec.image/on.png"));
            }


          }
    });









    //僚机2
    Wing_Btn2=new QPushButton;
    Wing_Btn2->setParent(this);
    Wing_Btn2->setIcon(QIcon(":/rec.image/buy.png"));
    Wing_Btn2->setIconSize(QSize(100,40));
    Wing_Btn2->setFixedSize(100,40);
    Wing_Btn2->move(350,350);
    Wing_Btn2->setFlat(true);
    Wing_Btn2->setAttribute(Qt::WA_TranslucentBackground);


    QLabel* l5=new QLabel;
    l5->setParent(this);
    QPixmap p5;
    p5.load(WING_PATH3);
    l5->setPixmap(p5);
    l5->move(380,280);
    QLabel*l5_gold=new QLabel;
    l5_gold->setParent(this);
    QPixmap p5_gold;
    p5_gold.load(":/rec.image/gold2.png");
    l5_gold->setPixmap(p5_gold);
    l5_gold->move(380,330);
    l5_gold->setFixedSize(20,20);
    QLabel*l5_num=new QLabel;
    l5_num->setParent(this);
    l5_num->setText(QString::number(WING2_VALUE));
    l5_num->move(400,330);
    l5_num->setStyleSheet("color:Yellow");



    //点击按钮 购买
    connect(Wing_Btn2,&QPushButton::clicked,[=](){
         btn_music->play();
        //弹出对话框
        QMessageBox msgBox;
        //对话框主题
        msgBox.setInformativeText("   是否购买？  ");
       // 对话框选项
        msgBox.setStandardButtons(QMessageBox::Yes |  QMessageBox::Cancel);
        //msgBox.setDefaultButton(QMessageBox::Save);
        //对话框图片
        QPixmap pix;
        pix.load(WING_PATH3);
        msgBox.setIconPixmap(pix);
        msgBox.setWindowTitle("购买战机");
        msgBox.setWindowIcon(QIcon(":/rec.image/Icon.png"));

        int ret = msgBox.exec();
        switch (ret) {
        case QMessageBox::Yes:
            if(gold_num<WING2_VALUE)
            {
                  QMessageBox::warning(this,"warn"," 金币不够");
            }
            else {
                gold_num-=WING2_VALUE;
                emit(BuyWing2());
                Wing_Btn2->setIcon(QIcon(":/rec.image/on.png"));
            }


          }
    });













    //僚机3
    Wing_Btn3=new QPushButton;
    Wing_Btn3->setParent(this);
    Wing_Btn3->setIcon(QIcon(":/rec.image/buy.png"));
    Wing_Btn3->setIconSize(QSize(100,40));
    Wing_Btn3->setFixedSize(100,40);
    Wing_Btn3->move(600,350);
    Wing_Btn3->setFlat(true);
    Wing_Btn3->setAttribute(Qt::WA_TranslucentBackground);


    QLabel* l6=new QLabel;
    l6->setParent(this);
    QPixmap p6;
    p6.load(WING_PATH4);
    l6->setPixmap(p6);
    l6->move(630,280);
    QLabel*l6_gold=new QLabel;
    l6_gold->setParent(this);
    QPixmap p6_gold;
    p6_gold.load(":/rec.image/gold2.png");
    l6_gold->setPixmap(p6_gold);
    l6_gold->move(630,330);
    l6_gold->setFixedSize(20,20);
    QLabel*l6_num=new QLabel;
    l6_num->setParent(this);
    l6_num->setText(QString::number(WING3_VALUE));
    l6_num->move(650,330);
    l6_num->setStyleSheet("color:Yellow");



    //点击按钮 购买
    connect(Wing_Btn3,&QPushButton::clicked,[=](){
         btn_music->play();
        //弹出对话框
        QMessageBox msgBox;
        //对话框主题
        msgBox.setInformativeText("   是否购买？  ");
       // 对话框选项
        msgBox.setStandardButtons(QMessageBox::Yes |  QMessageBox::Cancel);
        //msgBox.setDefaultButton(QMessageBox::Save);
        //对话框图片
        QPixmap pix;
        pix.load(WING_PATH4);
        msgBox.setIconPixmap(pix);
        msgBox.setWindowTitle("购买战机");
        msgBox.setWindowIcon(QIcon(":/rec.image/Icon.png"));

        int ret = msgBox.exec();
        switch (ret) {
        case QMessageBox::Yes:
            if(gold_num<WING3_VALUE)
            {
                  QMessageBox::warning(this,"warn"," 金币不够");
            }
            else {
                gold_num-=WING3_VALUE;
                emit(BuyWing3());
                Wing_Btn3->setIcon(QIcon(":/rec.image/on.png"));
            }


          }
    });










    //僚机4
    Wing_Btn4=new QPushButton;
    Wing_Btn4->setParent(this);
    Wing_Btn4->setIcon(QIcon(":/rec.image/buy.png"));
    Wing_Btn4->setIconSize(QSize(100,40));
    Wing_Btn4->setFixedSize(100,40);
    Wing_Btn4->move(100,500);
    Wing_Btn4->setFlat(true);
    Wing_Btn4->setAttribute(Qt::WA_TranslucentBackground);


    QLabel* l7=new QLabel;
    l7->setParent(this);
    QPixmap p7;
    p7.load(WING_PATH5);
    l7->setPixmap(p7);
    l7->move(130,430);
    QLabel*l7_gold=new QLabel;
    l7_gold->setParent(this);
    QPixmap p7_gold;
    p7_gold.load(":/rec.image/gold2.png");
    l7_gold->setPixmap(p7_gold);
    l7_gold->move(130,480);
    l7_gold->setFixedSize(20,20);
    QLabel*l7_num=new QLabel;
    l7_num->setParent(this);
    l7_num->setText(QString::number(WING4_VALUE));
    l7_num->move(150,480);
    l7_num->setStyleSheet("color:Yellow");


    //点击按钮 购买
    connect(Wing_Btn4,&QPushButton::clicked,[=](){
         btn_music->play();
        //弹出对话框
        QMessageBox msgBox;
        //对话框主题
        msgBox.setInformativeText("   是否购买？  ");
       // 对话框选项
        msgBox.setStandardButtons(QMessageBox::Yes |  QMessageBox::Cancel);
        //msgBox.setDefaultButton(QMessageBox::Save);
        //对话框图片
        QPixmap pix;
        pix.load(WING_PATH5);
        msgBox.setIconPixmap(pix);
        msgBox.setWindowTitle("购买战机");
        msgBox.setWindowIcon(QIcon(":/rec.image/Icon.png"));

        int ret = msgBox.exec();
        switch (ret) {
        case QMessageBox::Yes:
            if(gold_num<WING4_VALUE)
            {
                  QMessageBox::warning(this,"warn"," 金币不够");
            }
            else {
                gold_num-=WING4_VALUE;
                emit(BuyWing4());
                Wing_Btn4->setIcon(QIcon(":/rec.image/on.png"));
            }


          }
    });









    //僚机5
    Wing_Btn5=new QPushButton;
    Wing_Btn5->setParent(this);
    Wing_Btn5->setIcon(QIcon(":/rec.image/buy.png"));
    Wing_Btn5->setIconSize(QSize(100,40));
    Wing_Btn5->setFixedSize(100,40);
    Wing_Btn5->move(350,500);
    Wing_Btn5->setFlat(true);
    Wing_Btn5->setAttribute(Qt::WA_TranslucentBackground);


    QLabel* l8=new QLabel;
    l8->setParent(this);
    QPixmap p8;
    p8.load(WING_PATH6);
    l8->setPixmap(p8);
    l8->move(380,430);
    QLabel*l8_gold=new QLabel;
    l8_gold->setParent(this);
    QPixmap p8_gold;
    p8_gold.load(":/rec.image/gold2.png");
    l8_gold->setPixmap(p8_gold);
    l8_gold->move(380,480);
    l8_gold->setFixedSize(20,20);
    QLabel*l8_num=new QLabel;
    l8_num->setParent(this);
    l8_num->setText(QString::number(WING5_VALUE));
    l8_num->move(400,480);
    l8_num->setStyleSheet("color:Yellow");



    //点击按钮 购买
    connect(Wing_Btn5,&QPushButton::clicked,[=](){
         btn_music->play();
        //弹出对话框
        QMessageBox msgBox;
        //对话框主题
        msgBox.setInformativeText("   是否购买？  ");
       // 对话框选项
        msgBox.setStandardButtons(QMessageBox::Yes |  QMessageBox::Cancel);
        //msgBox.setDefaultButton(QMessageBox::Save);
        //对话框图片
        QPixmap pix;
        pix.load(WING_PATH6);
        msgBox.setIconPixmap(pix);
        msgBox.setWindowTitle("购买战机");
        msgBox.setWindowIcon(QIcon(":/rec.image/Icon.png"));

        int ret = msgBox.exec();
        switch (ret) {
        case QMessageBox::Yes:
            if(gold_num<WING5_VALUE)
            {
                  QMessageBox::warning(this,"warn"," 金币不够");
            }
            else {
                gold_num-=WING5_VALUE;
                emit(BuyWing5());
                Wing_Btn5->setIcon(QIcon(":/rec.image/on.png"));
            }


          }
    });













    //僚机6
    Wing_Btn6=new QPushButton;
    Wing_Btn6->setParent(this);
    Wing_Btn6->setIcon(QIcon(":/rec.image/buy.png"));
    Wing_Btn6->setIconSize(QSize(100,40));
    Wing_Btn6->setFixedSize(100,40);
    Wing_Btn6->move(600,500);
    Wing_Btn6->setFlat(true);
    Wing_Btn6->setAttribute(Qt::WA_TranslucentBackground);

    QLabel* l9=new QLabel;
    l9->setParent(this);
    QPixmap p9;
    p9.load(WING_PATH7);
    l9->setPixmap(p9);
    l9->move(630,430);
    QLabel*l9_gold=new QLabel;
    l9_gold->setParent(this);
    QPixmap p9_gold;
    p9_gold.load(":/rec.image/gold2.png");
    l9_gold->setPixmap(p9_gold);
    l9_gold->move(630,480);
    l9_gold->setFixedSize(20,20);
    QLabel*l9_num=new QLabel;
    l9_num->setParent(this);
    l9_num->setText(QString::number(WING6_VALUE));
    l9_num->move(650,480);
    l9_num->setStyleSheet("color:Yellow");



    //点击按钮 购买
    connect(Wing_Btn6,&QPushButton::clicked,[=](){
         btn_music->play();
        //弹出对话框
        QMessageBox msgBox;
        //对话框主题
        msgBox.setInformativeText("   是否购买？  ");
       // 对话框选项
        msgBox.setStandardButtons(QMessageBox::Yes |  QMessageBox::Cancel);
        //msgBox.setDefaultButton(QMessageBox::Save);
        //对话框图片
        QPixmap pix;
        pix.load(WING_PATH7);
        msgBox.setIconPixmap(pix);
        msgBox.setWindowTitle("购买战机");
        msgBox.setWindowIcon(QIcon(":/rec.image/Icon.png"));

        int ret = msgBox.exec();
        switch (ret) {
        case QMessageBox::Yes:
            if(gold_num<WING6_VALUE)
            {
                  QMessageBox::warning(this,"warn"," 金币不够");
            }
            else {
                gold_num-=WING6_VALUE;
                emit(BuyWing6());
                Wing_Btn6->setIcon(QIcon(":/rec.image/on.png"));

            }


          }
    });





    //按钮音效
    btn_music=new QSound(MUSIC_BTN);

}

void MyStore::paintEvent(QPaintEvent *event)
{
    QPixmap pix;
    pix.load(":/rec.image/store.png");

    QPainter painter(this);
    painter.drawPixmap(0,0,pix);
}
